#include<stdio.h>
int main()
{
    //freopen("in.txt","r",stdin);
    char str[1005];
    char command[150];
    scanf("%s",str);
    int q;
    scanf("%d",&q);
    for(int i = 0; i < q; i++)
    {
        scanf("%s",command);
        if(command[0] == 'p')
        {
            int a,b;
            scanf("%d %d",&a,&b);
            for(int i = a; i <= b; i++)
            {
                printf("%c",str[i]);
            }
            printf("\n");
        }
        if(command[0] == 'r' && command[2] == 'p')
        {
            int a,b;
            char p[10000];
            scanf("%d %d",&a,&b);
            scanf("%s",p);
            for(int i = a; i <= b; i++)
            {
                str[i] = p[i-a];
            }
            //printf("%s\n",str);
        }
        if(command[0] == 'r' && command[2] == 'v')
        {
            int a,b;
            scanf("%d %d",&a,&b);
            for(int i = a; i <= (a+b)/2; i++)
            {
                char temp = str[i];
                str[i] = str[b-i+a];
                str[b-i+a] = temp;
            }
            //printf("%s\n",str);
        }
    }
}